package com.pi.shisan.util.spipoint;

import com.pi.shisan.common.NumberUtil;
import com.pi.shisan.util.DefaultFont8x8;

public class SpiPoint extends BaseXyToSpi{

    @Override
    public void add(int x, int y) {
        checkXy(x, y);
        result[y] |= 1 << 7 - x;
    }

    @Override
    public void put(int x, int y) {
        x = convert(x);
        y = convert(y);
        result[y] |= 1 << 7 - x;
    }

    @Override
    public void put(int xy) {
        put(NumberUtil.toX(xy), NumberUtil.toY(xy));
    }

    @Override
    public void remove(int x, int y) {
        checkXy(x, y);
        result[y] &= ~(1 << 7 - x);
    }

    @Override
    public void delete(int x, int y) {
        x = convert(x);
        y = convert(y);
        result[y] &= ~(1 << 7 - x);
    }

    @Override
    public void delete(int xy) {
        delete(NumberUtil.toX(xy), NumberUtil.toY(xy));
    }

    @Override
    public String toString(){
        StringBuilder builder = new StringBuilder();
        for (int i = 0; i < result.length; i++) {
            for (int j = 0; j < 8; j++) {
                if (j > 0) {
                    builder.append(" ");
                }
                builder.append((1<<7-j&result[i])!=0?"◼":"○");
            }
            builder.append("\n");
        }
        return builder.toString();
    }

    public static void main(String[] args) {

        XyToSpiHolder toSpi = new SpiPoint();
        int[] pointsAsXy = DefaultFont8x8.getPointsAsXy(26647025581568L);
        for (int i = 0; i < pointsAsXy.length; i++) {
            toSpi.put(pointsAsXy[i]);
        }
        System.out.println(toSpi.toString());

    }
}
